<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>org.apache.commons.io.comparator (Apache Commons IO 2.5 API)</title>
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
    if (location.href.indexOf('is-external=true') == -1) {
        parent.document.title="org.apache.commons.io.comparator (Apache Commons IO 2.5 API)";
    }
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!--   -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">Package</li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/commons/io/package-summary.html">Prev Package</a></li>
<li><a href="../../../../../org/apache/commons/io/filefilter/package-summary.html">Next Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/commons/io/comparator/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<a name="skip-navbar_top">
<!--   -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h1 title="Package" class="title">Package&nbsp;org.apache.commons.io.comparator</h1>
<div class="docSummary">
<div class="block">This package provides various <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util"><code>Comparator</code></a> implementations
for <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io"><code>File</code></a>s.</div>
</div>
<p>See:&nbsp;<a href="#package_description">Description</a></p>
</div>
<div class="contentContainer">
<ul class="blockList">
<li class="blockList">
<table class="packageSummary" border="0" cellpadding="3" cellspacing="0" summary="Class Summary table, listing classes, and an explanation">
<caption><span>Class Summary</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Class</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/CompositeFileComparator.html" title="class in org.apache.commons.io.comparator">CompositeFileComparator</a></td>
<td class="colLast">
<div class="block">Compare two files using a set of delegate file <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util"><code>Comparator</code></a>.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/DefaultFileComparator.html" title="class in org.apache.commons.io.comparator">DefaultFileComparator</a></td>
<td class="colLast">
<div class="block">Compare two files using the <b>default</b> <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#compareTo(java.io.File)" title="class or interface in java.io"><code>File.compareTo(File)</code></a> method.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/DirectoryFileComparator.html" title="class in org.apache.commons.io.comparator">DirectoryFileComparator</a></td>
<td class="colLast">
<div class="block">Compare two files using the <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#isDirectory()" title="class or interface in java.io"><code>File.isDirectory()</code></a> method.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/ExtensionFileComparator.html" title="class in org.apache.commons.io.comparator">ExtensionFileComparator</a></td>
<td class="colLast">
<div class="block">Compare the file name <b>extensions</b> for order
 (see <a href="../../../../../org/apache/commons/io/FilenameUtils.html#getExtension(java.lang.String)"><code>FilenameUtils.getExtension(String)</code></a>).</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/LastModifiedFileComparator.html" title="class in org.apache.commons.io.comparator">LastModifiedFileComparator</a></td>
<td class="colLast">
<div class="block">Compare the <b>last modified date/time</b> of two files for order 
 (see <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#lastModified()" title="class or interface in java.io"><code>File.lastModified()</code></a>).</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/NameFileComparator.html" title="class in org.apache.commons.io.comparator">NameFileComparator</a></td>
<td class="colLast">
<div class="block">Compare the <b>names</b> of two files for order (see <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#getName()" title="class or interface in java.io"><code>File.getName()</code></a>).</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/PathFileComparator.html" title="class in org.apache.commons.io.comparator">PathFileComparator</a></td>
<td class="colLast">
<div class="block">Compare the <b>path</b> of two files for order (see <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#getPath()" title="class or interface in java.io"><code>File.getPath()</code></a>).</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../../org/apache/commons/io/comparator/SizeFileComparator.html" title="class in org.apache.commons.io.comparator">SizeFileComparator</a></td>
<td class="colLast">
<div class="block">Compare the <b>length/size</b> of two files for order (see
 <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true#length()" title="class or interface in java.io"><code>File.length()</code></a> and <a href="../../../../../org/apache/commons/io/FileUtils.html#sizeOfDirectory(java.io.File)"><code>FileUtils.sizeOfDirectory(File)</code></a>).</div>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<a name="package_description">
<!--   -->
</a>
<h2 title="Package org.apache.commons.io.comparator Description">Package org.apache.commons.io.comparator Description</h2>
<div class="block"><p>This package provides various <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util"><code>Comparator</code></a> implementations
for <a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html?is-external=true" title="class or interface in java.io"><code>File</code></a>s.
</p>
<h3>Sorting</h3>
<p>
  All the compartors include <i>convenience</i> utility <code>sort(File...)</code> and
  <code>sort(List)</code> methods.
</p>
<p>
  For example, to sort the files in a directory by name:
</p>
  <pre>
        File[] files = dir.listFiles();
        NameFileComparator.NAME_COMPARATOR.sort(files);
  </pre>
<p>
  ...alternatively you can do this in one line:
</p>
<p>
  <pre>
        File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());
  </pre>
</p>

<h3>Composite Comparator</h3>
<p>
  The <a href="CompositeFileComparator.html">CompositeFileComparator</a> can be used
  to compare (and sort lists or arrays of files) by combining a number other comparators.
</p>
<p>
  For example, to sort an array of files by type (i.e. directory or file)
  and then by name:
</p>
<p>
  <pre>
        CompositeFileComparator comparator =
                        new CompositeFileComparator(
                                    DirectoryFileComparator.DIRECTORY_COMPARATOR,
                                    NameFileComparator.NAME_COMPARATOR);
        File[] files = dir.listFiles();
        comparator.sort(files);
  </pre>
</p>

<h3>Singleton Instances (thread-safe)</h3>
<p>
 The <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Comparator.html?is-external=true" title="class or interface in java.util"><code>Comparator</code></a> implementations have some <i>convenience</i>
 singleton(<i>thread-safe</i>) instances ready to use:
 <ul>
    <li><a href="DefaultFileComparator.html">DefaultFileComparator</a> - default file compare:
        <ul>
           <li><a href="DefaultFileComparator.html#DEFAULT_COMPARATOR">DEFAULT_COMPARATOR</a>
               - Compare using <code>File.compareTo(File)</code> method.
           </li>
           <li><a href="DefaultFileComparator.html#DEFAULT_REVERSE">DEFAULT_REVERSE</a>
               - Reverse compare of <code>File.compareTo(File)</code> method.
           </li>
        </ul>
    </li>
    <li><a href="DirectoryFileComparator.html">DirectoryFileComparator</a> - compare by type (directory or file):
        <ul>
           <li><a href="DirectoryFileComparator.html#DIRECTORY_COMPARATOR">DIRECTORY_COMPARATOR</a>
               - Compare using <code>File.isDirectory()</code> method (directories < files).
           </li>
           <li><a href="DirectoryFileComparator.html#DIRECTORY_REVERSE">DIRECTORY_REVERSE</a>
               - Reverse compare of <code>File.isDirectory()</code> method  (directories > files).
           </li>
        </ul>
    </li>
    <li><a href="ExtensionFileComparator.html">ExtensionFileComparator</a> - compare file extenstions:
        <ul>
           <li><a href="ExtensionFileComparator.html#EXTENSION_COMPARATOR">EXTENSION_COMPARATOR</a>
               - Compare using <code>FilenameUtils.getExtension(String)</code> method.
           </li>
           <li><a href="ExtensionFileComparator.html#EXTENSION_REVERSE">EXTENSION_REVERSE</a>
               - Reverse compare of <code>FilenameUtils.getExtension(String)</code> method.
           </li>
           <li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_COMPARATOR">EXTENSION_INSENSITIVE_COMPARATOR</a>
               - Case-insensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
           </li>
           <li><a href="ExtensionFileComparator.html#EXTENSION_INSENSITIVE_REVERSE">EXTENSION_INSENSITIVE_REVERSE</a>
               - Reverse case-insensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
           </li>
           <li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_COMPARATOR">EXTENSION_SYSTEM_COMPARATOR</a>
               -  System sensitive compare using <code>FilenameUtils.getExtension(String)</code> method.
           </li>
           <li><a href="ExtensionFileComparator.html#EXTENSION_SYSTEM_REVERSE">EXTENSION_SYSTEM_REVERSE</a>
               - Reverse system sensitive compare of <code>FilenameUtils.getExtension(String)</code> method.
           </li>
        </ul>
    </li>
    <li><a href="LastModifiedFileComparator.html">LastModifiedFileComparator</a>
        - compare the file's last modified date/time:
        <ul>
           <li><a href="LastModifiedFileComparator.html#LASTMODIFIED_COMPARATOR">LASTMODIFIED_COMPARATOR</a>
               - Compare using <code>File.lastModified()</code> method.
           </li>
           <li><a href="LastModifiedFileComparator.html#LASTMODIFIED_REVERSE">LASTMODIFIED_REVERSE</a>
               - Reverse compare of <code>File.lastModified()</code> method.
           </li>
        </ul>
    </li>
     <li><a href="NameFileComparator.html">NameFileComparator</a> - compare file names:
        <ul>
           <li><a href="NameFileComparator.html#NAME_COMPARATOR">NAME_COMPARATOR</a>
               - Compare using <code>File.getName()</code> method.
           </li>
           <li><a href="NameFileComparator.html#NAME_REVERSE">NAME_REVERSE</a>
               - Reverse compare of <code>File.getName()</code> method.
           </li>
           <li><a href="NameFileComparator.html#NAME_INSENSITIVE_COMPARATOR">NAME_INSENSITIVE_COMPARATOR</a>
               - Case-insensitive compare using <code>File.getName()</code> method.
           </li>
           <li><a href="NameFileComparator.html#NAME_INSENSITIVE_REVERSE">NAME_INSENSITIVE_REVERSE</a>
               - Reverse case-insensitive compare of <code>File.getName()</code> method.
           </li>
           <li><a href="NameFileComparator.html#NAME_SYSTEM_COMPARATOR">NAME_SYSTEM_COMPARATOR</a>
               -  System sensitive compare using <code>File.getName()</code> method.
           </li>
           <li><a href="NameFileComparator.html#NAME_SYSTEM_REVERSE">NAME_SYSTEM_REVERSE</a>
               - Reverse system sensitive compare of <code>File.getName()</code> method.
           </li>
        </ul>
    </li>
     <li><a href="PathFileComparator.html">PathFileComparator</a> - compare file paths:
        <ul>
           <li><a href="PathFileComparator.html#PATH_COMPARATOR">PATH_COMPARATOR</a>
               - Compare using <code>File.getPath()</code> method.
           </li>
           <li><a href="PathFileComparator.html#PATH_REVERSE">PATH_REVERSE</a>
               - Reverse compare of <code>File.getPath()</code> method.
           </li>
           <li><a href="PathFileComparator.html#PATH_INSENSITIVE_COMPARATOR">PATH_INSENSITIVE_COMPARATOR</a>
               - Case-insensitive compare using <code>File.getPath()</code> method.
           </li>
           <li><a href="PathFileComparator.html#PATH_INSENSITIVE_REVERSE">PATH_INSENSITIVE_REVERSE</a>
               - Reverse case-insensitive compare of <code>File.getPath()</code> method.
           </li>
           <li><a href="PathFileComparator.html#PATH_SYSTEM_COMPARATOR">PATH_SYSTEM_COMPARATOR</a>
               -  System sensitive compare using <code>File.getPath()</code> method.
           </li>
           <li><a href="PathFileComparator.html#PATH_SYSTEM_REVERSE">PATH_SYSTEM_REVERSE</a>
               - Reverse system sensitive compare of <code>File.getPath()</code> method.
           </li>
        </ul>
    </li>
    <li><a href="SizeFileComparator.html">SizeFileComparator</a> - compare the file's size:
        <ul>
           <li><a href="SizeFileComparator.html#SIZE_COMPARATOR">SIZE_COMPARATOR</a>
               - Compare using <code>File.length()</code> method (directories treated as zero length).
           </li>
           <li><a href="SizeFileComparator.html#SIZE_REVERSE">LASTMODIFIED_REVERSE</a>
               - Reverse compare of <code>File.length()</code> method (directories treated as zero length).
           </li>
           <li><a href="SizeFileComparator.html#SIZE_SUMDIR_COMPARATOR">SIZE_SUMDIR_COMPARATOR</a>
               - Compare using <code>FileUtils.sizeOfDirectory(File)</code> method
                (sums the size of a directory's contents).
           </li>
           <li><a href="SizeFileComparator.html#SIZE_SUMDIR_REVERSE">SIZE_SUMDIR_REVERSE</a>
               - Reverse compare of <code>FileUtils.sizeOfDirectory(File)</code> method
                (sums the size of a directory's contents).
           </li>
        </ul>
    </li>
 </ul>
</p></div>
</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!--   -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">Package</li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../org/apache/commons/io/package-summary.html">Prev Package</a></li>
<li><a href="../../../../../org/apache/commons/io/filefilter/package-summary.html">Next Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?org/apache/commons/io/comparator/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<a name="skip-navbar_bottom">
<!--   -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright &#169; 2002&#x2013;2016 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>
